import { HttpServer } from './src/utils/httpServer.js'
import config from './config.json' assert { type: 'json' }
import router from './src/route/index.js'
import { db } from './src/db/index.js'
import mqttClient from './src/mqtt/index.js'
import logger from './src/utils/logger.js'

db.createAllTable()
const { port, hostname } = config
new HttpServer({ port, hostname, router })

// 进程结束，清理 mqtt 连接
process.on('SIGINT', () => {
    logger.info('process exit!')
    mqttClient.end(() => {
        logger.info('[MQTT] end')
        process.exit()
    })
})
